/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.poc.base.node;

import com.herenit.beijing.dh2011.security.entity.SecurityMenu;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import org.openide.filesystems.FileObject;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author Obama
 */
public class MenuChildrenFactory extends ChildFactory<SecurityMenu> {

    static List<SecurityMenu> securityMenus;
    SecurityMenu securityMenu;

    public MenuChildrenFactory(List<SecurityMenu> securityMenus, SecurityMenu securityMenu) {
        this.securityMenus = securityMenus;
        this.securityMenu = securityMenu;
    }

    @Override
    protected boolean createKeys(List toPopulate) {

        for (SecurityMenu menu : securityMenus) {
            if ( menu.getFatherId() != null && securityMenu.getMenuId() != null && securityMenu.getMenuId().equals(menu.getFatherId().getMenuId())) {
                toPopulate.add(menu);
            } 
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(SecurityMenu key) {
        return new MenuNode(key, Children.create(new MenuChildrenFactory(securityMenus, key), false));
    }
}
